package com.rose.doorto.footbathdoor.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import com.rose.doorto.footbathdoor.enums.PayType;
import com.rose.doorto.footbathdoor.mapper.PaymentInfoMapper;
import com.rose.doorto.footbathdoor.pojo.PaymentInfoEntity;
import com.rose.doorto.footbathdoor.service.PaymentInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author 李庆超
 * @email 1481791489@qq.com
 * @Package：com.rose.doorto.footbathdoor.service.impl
 * @Project：door-to-door
 * @name：PaymentInfoServiceImpl
 * @date 2024/08/28 2024/8/28:10:29:
 */
@Slf4j
@Transactional
@Service
public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, PaymentInfoEntity> implements PaymentInfoService {


    @Autowired
    private PaymentInfoMapper paymentInfoMapper;
    /**
     * 记录支付日志：支付宝
     *
     * @param params
     */
    @Override
    public void createPaymentInfoForAliPay(Map<String, String> params) {

        log.info("记录支付日志");

        //获取订单号
        String orderNo = params.get("out_trade_no");
        //业务编号
        String transactionId = params.get("trade_no");
        //交易状态
        String tradeStatus = params.get("trade_status");
        //交易金额
        String totalAmount = params.get("total_amount");
        int totalAmountInt = new BigDecimal(totalAmount).multiply(new BigDecimal("100")).intValue();


        PaymentInfoEntity paymentInfo = new PaymentInfoEntity();
        paymentInfo.setOrderSn(orderNo);      //订单号
        paymentInfo.setPayType(1);
//        paymentInfo.setTransactionId(transactionId);
//        paymentInfo.setTradeType("电脑网站支付");
        paymentInfo.setPaymentStatus(tradeStatus);  //支付状态
        paymentInfo.setTotalAmount(totalAmount);    //支付总金额
        paymentInfo.setCreateTime(new Date());      //创建时间

        Gson gson = new Gson();
        String json = gson.toJson(params, HashMap.class);
        paymentInfo.setContent(json);

        paymentInfoMapper.insert(paymentInfo);
    }
}


